/*
The MIT License (MIT)

Copyright (c) 2013 Mike Dapiran, Brian May, Richard Pospesel, and Bert Wierenga

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once

#include "OutputStream.h"

namespace Hogshead
{
	namespace Common
	{
		class String;

		/**
		* PrintStream is a wrapper class for other OutputStreams.  It takes
		* and stores another OutputStream and provides plain text printing for
		* various primitive types and for String.  Additional objects can be
		* made to operate with the << operator by making a friend operator
		* overload in that class.
		*
		* Note that the close() method doesn't do anything and to close the
		* underlying stream, close() must be called on it directly.
		*/
		class PrintStream : public OutputStream
		{
		public:
			PrintStream();


			/**
			* Constructor for PrintStream takes a reference to another OutputStream
			* @param in_output_stream An OutputStream to wrap with a PrintStream.
			*/
			PrintStream(OutputStream& in_output_stream);
			/**
			* Simply calls the underlying OutputStream's flush() method.
			*/
			void flush();
			/**
			* Simply calls the underlying OutputStream's write(char) method.
			*/
			void write(char in_char);
			/**
			* Simply calls the underlying OutputStream's write(const char*, unsigned int) method.
			*/
			void write(const char* in_bytes, unsigned int in_count);
#pragma region BITSHIFT_OVERLOADS
			/**
			* This operator overload allows us to have custom functions which work
			* on the PrintStream.  For instance, endl writes a '\n' character
			* and calls the flush() method.
			* @param pf A function which takes a PrintStream& and returns a PrintStream&
			* @return returns this PrintStream as a reference for chaining the << operator.
			*/
			PrintStream& operator<<(PrintStream& (*pf)(PrintStream&));

			// overloads for primitive types
			// integer types
			PrintStream& operator<<(const char* in_string);
			PrintStream& operator<<(char in_char);
			PrintStream& operator<<(unsigned char in_uchar);
			PrintStream& operator<<(bool in_bool);
			PrintStream& operator<<(int in_int);
			PrintStream& operator<<(unsigned int in_uint);
			PrintStream& operator<<(long long in_long);
			PrintStream& operator<<(unsigned long long in_ulong);
			// floating point
			PrintStream& operator<<(float in_float);
			PrintStream& operator<<(double in_double);
			// other
			PrintStream& operator<<(const void* in_pointer);
			PrintStream& operator<<(const String& in_string);
#pragma endregion

		private:
			// pointer to the stream we are using
			OutputStream* _output_stream;
		};

		// writes a '\n' character to the stream
		PrintStream& endl(PrintStream& in_stream);
		// flushes the stream using flush()
		PrintStream& flush(PrintStream& in_stream);

		
	}
}

